package main

import (
    "fmt"
    "sort"
)

func solution(a, b []int) []int {
    setA := make(map[int]bool)
    setB := make(map[int]bool)

    // 构建集合
    for _, num := range a {
        setA[num] = true
    }
    for _, num := range b {
        setB[num] = true
    }

    // 求交集：在 a 中且在 b 中的元素（自动去重）
    var result []int
    for num := range setA {
        if setB[num] {
            result = append(result, num)
        }
    }

    // 降序排序
    sort.Slice(result, func(i, j int) bool {
        return result[i] > result[j]
    })

    return result
}

func main() {
    // 测试用例
    fmt.Println(sliceEqual(solution([]int{1, 2, 3, 7}, []int{2, 5, 7}), []int{7, 2}))
    fmt.Println(sliceEqual(solution([]int{1, 4, 8, 10}, []int{2, 4, 8, 10}), []int{10, 8, 4}))
    fmt.Println(len(solution([]int{3, 5, 9}, []int{1, 4, 6})) == 0)
    fmt.Println(sliceEqual(solution([]int{1, 2, 3}, []int{1, 2, 3}), []int{3, 2, 1}))
}

// 辅助函数：比较两个切片是否相等
func sliceEqual(a, b []int) bool {
    if len(a) != len(b) {
        return false
    }
    for i := range a {
        if a[i] != b[i] {
            return false
        }
    }
    return true
}